package com.examples.controls.concepts;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;

public class MoveBasic {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Display display = Display.getDefault();
		final Shell shell1 = new Shell(display);
		shell1.pack();
		shell1.open();
		final Shell shell2 = new Shell(shell1, SWT.NONE);
		shell2.pack();
		shell2.open();
		
		Rectangle rect = shell1.getBounds();
		shell2.setLocation(rect.x + rect.width + 2, rect.y + 5);
		
		shell1.addListener(SWT.Move, new Listener() {
			public void handleEvent(Event e) {
				Rectangle rect = shell1.getBounds();
				shell2.setLocation(rect.x + rect.width, rect.y);
			}
		});
		while (!shell1.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}

		//display.dispose(); //Commented only for SWTShowcase application.

	}

}
